﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using YArchitech.LIB.YJKControls;

namespace SystemDiagramNew
{
	public partial class LabelPipeElevationForm : System.Windows.Forms.Form
	{
		public LabelPipeElevationForm()
		{
			this.InitializeComponent();
		}

		public LabelPipeElevationForm.LabelType TheLabelType()
		{
			if (this.rdbNearInside.Checked)
			{
				return LabelPipeElevationForm.LabelType.LT_NearInside;
			}
			if (this.rdbNearExternal.Checked)
			{
				return LabelPipeElevationForm.LabelType.LT_NearExternal;
			}
			return LabelPipeElevationForm.LabelType.LT_SelectPoint;
		}

		private void LabelPipeElevationForm_Load(object sender, EventArgs e)
		{
			string tempPath = Path.GetTempPath();
			string path = tempPath + "LabelPipeElevationForm.dat";
			if (!File.Exists(path))
			{
				this.rdbNearInside.Checked = true;
				this.rdbNearExternal.Checked = false;
				this.rdbSelectPoint.Checked = false;
				return;
			}
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			this.rdbNearInside.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.rdbNearExternal.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.rdbSelectPoint.Checked = Convert.ToBoolean(streamReader.ReadLine());
			streamReader.Close();
			fileStream.Close();
		}

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		private void LabelPipeElevationForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			string tempPath = Path.GetTempPath();
			string path = tempPath + "LabelPipeElevationForm.dat";
			FileStream fileStream = new FileStream(path, FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.WriteLine(this.rdbNearInside.Checked);
			streamWriter.WriteLine(this.rdbNearExternal.Checked);
			streamWriter.WriteLine(this.rdbSelectPoint.Checked);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
			byte bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			LabelPipeElevationForm.keybd_event(bVk, 0, dwFlags, 0);
			LabelPipeElevationForm.keybd_event(bVk, 0, dwFlags2, 0);
		}

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		private void LabelPipeElevationForm_MouseLeave(object sender, EventArgs e)
		{
		}

		public enum LabelType
		{
			LT_NearInside,
			LT_NearExternal,
			LT_SelectPoint
		}
	}
}
